#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

void Copy(int* table, int tableSourceRow, int tableSourceCol, int tableDestinationRow, int tableDestinationCol, int size,const int number)
{
	for (int iS = tableSourceRow, iD = tableDestinationRow; iS < tableSourceRow + size && iD < tableDestinationRow + size; iS++, iD++)
	{
		for (int jS = tableSourceCol, jD = tableDestinationCol; jS < tableSourceCol + size && jD < tableDestinationCol + size; jS++, jD++)
		{
			table[iD*number + jD] = table[iS*number + jS];
		}
	}
}
void RoundRobinSchedule(int* table, int topRow, int topCol, int size,const int number)
{
	static int count = 1;
	if (size == 1)
	{
		table[topRow*size+topCol] = count++;
		return;
	}
	RoundRobinSchedule(table, topRow, topCol, size / 2,number);
	RoundRobinSchedule(table, topRow, topCol + size / 2, size / 2,number);
	Copy(table, topRow, topCol, topRow + size / 2, topCol + size / 2, size / 2,number);
	Copy(table, topRow, topCol + size / 2, topRow + size / 2, topCol, size / 2,number);
}

void PrintTable(int* table, int size)
{
	cout << endl;
	for (int i = 0; i < size; i++)
	{
		for (int j = 0; j < size; j++)
		{
			cout << table[i*size + j] << " ";
		}
		cout << endl;
	}
}
int main()
{
	int number;
	cout << "Please input tne number of participants:>";
	do
	{
		cin >> number;
		if (number % 2 == 0)
			break;
		else
			cout << "Input fail,please input again:>" << endl;
	} while (1);

	int* table = new int[number*number];
	RoundRobinSchedule(table, 0, 0, number,number);
	PrintTable(table, number);
	delete[] table;
	return 0;
}